"""
author:俞婧，田新宇,杨光
create time:2020-07-08
update time:2020-07-21
"""

from django.db import models

# Create your models here.
class User(models.Model):
    '''用户表'''
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=128,unique=True)
    password = models.CharField(max_length=256)
    email = models.EmailField(unique=True) #,default='无'
    nick_name = models.CharField(max_length=128,default='无')#昵称
    sign = models.CharField(max_length=255,default='无')#个性签名
    c_time = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.name

    class Meta:
        ordering = ['c_time']
        verbose_name = '用户'
        verbose_name_plural = '用户'

class course(models.Model):
    '''课程表'''
    id = models.AutoField(primary_key=True)
    course_name = models.CharField(max_length=128)
    course_school = models.CharField(max_length=128)  # 大学
    course_teacher = models.CharField(max_length=128,default='无')#老师
    course_type = models.CharField(max_length=128, default='无')#课程类型
    course_time = models.CharField(max_length=128, default='无')  # 开课时间
    course_status = models.CharField(max_length=255,default='无')#课程状态
    course_credit = models.CharField(max_length=128, default='无')  # 学分
    course_content = models.CharField(max_length=3000,default='无')#课程概述
    course_outline = models.CharField(max_length=2000,default='无')#课程目标
    course_img =models.ImageField(upload_to="img/",default='')

    course_student = models.ManyToManyField(User,blank=True)#与用户（学生）多对多
    class Meta:
        verbose_name = '课程'
        verbose_name_plural = verbose_name

class course_user(models.Model):
    id = models.AutoField(primary_key=True)
    course = models.ForeignKey(course, on_delete=models.CASCADE)
    user = models.ForeignKey(User, on_delete=models.CASCADE)
